import React from 'react';
import { observer, inject } from "mobx-react/index";
import {getAntd, getEcCom, getLabel} from "../../util/convert";
import base from "../../util/base";
import {toJS} from 'mobx';


export default class Index extends React.Component{
  state={
    submitSelected:2,
    nodeid:-1
  }
  render(){
    const {changeSubmitParam,setProperty,submitSelected,freeNodeDatas} = base.globalStore;
    const options = toJS(freeNodeDatas).map((item,index)=>{
      let {nodeEntity={}} = item;
      let {operatorReplaceDatas=[],nodename}=nodeEntity;
      let showname = operatorReplaceDatas.length>0?operatorReplaceDatas[0].name:nodename;
      if(index==0 && this.state.nodeid==-1){
        this.setState({nodeid:item.nodeid+""});
        changeSubmitParam({SubmitToNodeid:item.nodeid,flowToNextFreeNode:""});
      }
      return {
        key:item.nodeid+"",
        showname
      }
    });
    const {Radio} = getAntd();
    const {WeaSelect} = getEcCom();
    const RadioGroup = Radio.Group;

    return <div>
      <div>{`${getLabel(507410,'请选择流转路径')}:`}</div>
      <div style={{'marginTop':'10px'}}>
        <RadioGroup onChange={(e)=> {
          if(e.target.value<=1){
            changeSubmitParam({'flowToNextFreeNode':e.target.value,SubmitToNodeid:""});
          }else{
            changeSubmitParam({SubmitToNodeid:this.state.nodeid,flowToNextFreeNode:""});
          }
          this.setState({submitSelected:e.target.value})

        }} defaultValue = {'2'}>
          <Radio value={'2'} style={{marginRight:"30px"}}>
            <span style={{verticalAlign: "middle",marginRight: "5px"}}>提交至</span>
            <WeaSelect
                hasBorder={false}
                options={options}
                value={this.state.nodeid}
                viewAttr={2}
                onChange={v => {
                  this.setState({ nodeid: v });
                  if(this.state.submitSelected==2){
                    changeSubmitParam({SubmitToNodeid:v});
                  }
                }}
            />
          </Radio>
          <Radio value={'0'}>{getLabel(533158,"结束审批")}</Radio>
        </RadioGroup>
      </div>
    </div>
  }
}